#include "adept.h"

#include "database.h"

Adept::Adept()
  : _circle(1)
{
}

void Adept::setTalentRank(const Talent &t, int rank)
{
  if (rank == 0) _talents.remove(t);
  else _talents[t] = rank;
}

int Adept::talentRank(const Talent &t) const
{
  if (!_talents.contains(t)) return 0;
  return _talents[t];
}

void Adept::set_discipline(const Discipline &d)
{
  _discipline = d;
  _spells << Database::spells(_discipline,1);
}

void Adept::addSpecialization(const Specialization &s)
{
  Q_ASSERT(!_specializations.contains(s));
  _specializations << s;
}

bool Adept::hasSpecialization(const Specialization &s) const
{
  return _specializations.contains(s);
}

void Adept::raiseCircle()
{
  ++_circle;
  QMap<ed::Characteristic,int> bonuses = _discipline.bonuses(_circle);
  foreach(ed::Characteristic c, bonuses.keys())
  {
    _characteristicBonuses[c] += bonuses[c];
  }
  _spells << Database::spells(_discipline,_circle);
}

int Adept::maximumKarma() const
{
  int bonus = 0;
  for (int c=1;c<=_circle;++c) bonus += _discipline.karmaBonus(c);
  return NameGiver::maximumKarma() + bonus;
}

int Adept::characteristicBonus(ed::Characteristic c) const
{
  int adeptBonus = 0;
  if (c == ed::Char_Uncounciousness) adeptBonus = talentRank(Database::talent("Endurance")) * _discipline.endurance().second;
  if (c == ed::Char_Death) adeptBonus = talentRank(Database::talent("Endurance")) * _discipline.endurance().first;
  return adeptBonus+NameGiver::characteristicBonus(c);
}

QStringList Adept::karmaUsages() const
{
  QStringList result;
  for (int c=1;c<=circle(); ++c)
  {
    result << _discipline.karmaUsages(c);
  }
  return result;
}
